<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Products extends MY_Controller {

    var $_templates = array();
    var $_lang = '';

    function __construct() {
        parent::__construct();
        $this->session->set_userdata(array('Url' => uri_string()));
        $this->_lang = $this->lang->lang();
        $this->load->model('product_model', 'products');
        $this->load->library('string_library');
        $this->load->library('securimage');
    }

    public function index() {
        $data = array();
        $str_product_id = end($this->uri->segment_array());
        $str_product = str_replace('item-', '', $str_product_id);
        $product_id = str_replace('.html', '', $str_product);
        $data['productItem'] = $this->products->getProductFromId($product_id);
        if ($data['productItem']) {
            $data['optionSize'] = $this->products->optionSize($product_id);
            $data['optionColor'] = $this->products->optionColor($product_id);
            $arr_root = $this->products->getRootParent($data['productItem']->product_category_id);
            $update_view = $this->products->update_View($data['productItem']->products_id, ($data['productItem']->viewed) + 1);
            $data['arr_rootPath'] = $arr_root;
            $str_keywords = $data['productItem']->meta_tags;
            $data['arr_keywords'] = explode(",", $str_keywords);
            $data['otherProducts'] = $this->products->getOtherFromCategory($data['productItem']->product_category_id, $product_id);
            $data['needviewProducts'] = $this->products->getOtherFromCategoryRandom();
            $data['pageTitle'] = $data['productItem']->name . ' - deal giá rẻ,giảm giá tại tphcm với chất lượng cam kết';
        }
        $data['products'] = $this->products;
        $data['url_detail'] = base_url() . $_SERVER["REQUEST_URI"];
        $this->_templates['page'] = 'product/detail_view';
        $this->site_lib->load($this->_templates['page'], $data, 'detail');
    }

    public function quantity() {
        $productId = $this->input->post('product_id');
        $quanlity = $this->input->post('quanlity');
        $json = array();
        $json['status'] = true;
        $json['message'] = "Liên hệ với admin để mua số lượng lớn hơn!";
        echo json_encode($json);
        exit();
    }

}

/* End of file home.php */
/* Location: ./application/controllers/home.php */